<script>
  var doupdate='__URL__/doupdate';
  var dolinkage='__URL__/dolinkage';
  var dogetinputselectlsbykw='__URL__/dogetinputselectlsbykw';
  var obj=new Object();
  var addormdf="{$id}";
  obj["{$lowmdmk}"+"id"]="{$id}";
  var editor=new Object();
</script>
<!--table部分-->
<!--pt I start-->
 <link rel="stylesheet" type="text/css" href="__PUBLIC__/etc/huploadify/html5uploader.css"/>
<script type="text/javascript" src="__PUBLIC__/etc/huploadify/jquery.html5uploader.js"></script>
<script>var dogivetail='__APP__/Hupldf/dogivetail'</script>
<!--pt I over-->
<!--ctt I start-->
<script type="text/javascript">var project="{$project}";</script>
<link rel="stylesheet" href="__PUBLIC__/etc/ueditor/themes/default/ueditor.css"/>
<script type="text/javascript" src="__PUBLIC__/etc/ueditor/editor_config.js"></script>
<script type="text/javascript" src="__PUBLIC__/etc/ueditor/editor_all.js"></script>
<!--ctt I over-->
<div class='col-md-12' style='padding-top: 20px'>
  <!--开始-->
  <table class='table table-hover table-striped table-bordered'>
    <tbody>
      <?php foreach($para as $k=>$v){
          if(!in_array($k, $no_update)){
       ?>
      <tr><td>{$v}</td><td>
      <?php if(in_array($k, $pic)){ ?>
      <?php if($moforjs[$k]){ $picpath=$moforjs[$k]; }else{ $picpath=$pic_dflt; } ?>
      
      <!--pt II start-->
      <script type="text/javascript">
      $(function(){
        $('#upload_{$k}').html5uploader({
          fileTypeExts:'image/jpeg,image/png',
          auto:true,
          multi:false,
          removeTimeout:0,
          url:'__APP__/Hupldf/upload/folder/common',//
          onUploadStart:function(){
            //alert('开始上传');
            var timestamp = (new Date()).valueOf();
          },
          onInit:function(){
            //alert('初始化');
          },
          onUploadComplete:function(file){
            //alert('上传完成');
            $.post(
              '__APP__/Hupldf/showphoto',
              {},
              function(data){
                $('#imgg_{$k}').attr('src',data.myfl);
                $('#{$k}').val(data.myfl);
              },
              'json'
            );
          }
        });
      });
      </script>
      <div><img src='{$picpath}' class='thumbnail' style='max-height:80px' id='imgg_{$k}' /><input type='hidden' id='{$k}' value="{$moforjs[$k]}"/></div>
      <div id="upload_{$k}"></div>
      <!--pt II over-->
      <?php }else if(in_array($k, $ctt)){ ?>

      <!--ctt II start-->
      <div>
        <div id="myEditor_{$k}">
        <script type="text/javascript">
          editor['{$k}'] = new baidu.editor.ui.Editor({
              initialContent: '<?php echo $moforjs[$k] ?>'
          });
          editor['{$k}'].render("myEditor_{$k}");
        </script>
        </div>
      </div>
      <textarea id='{$k}' style='display:none'></textarea>
      <!--ctt II over-->

      <?php }else if(strstr($k, '_')){ ?>
      <?php if(in_array($k, $inputselect)){ ?>
      <?php //处理萃取下主题
              $tmp=explode('_', $k);$tmp=explode('id',$tmp[2]);$tmp=$tmp[0];
          ?>
          <input class='cdt' type='hidden' id='{$k}'><!--这玩意会公版赋值的-->
          <span class="dropdown">
              <span id="dLabel_{$tmp}"  data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                  <input placeholder="输入{$v}" type="text" id='{$k}_ipt' value='<?php echo $inputselect_ipt_vl[$k]  ?>' class="keyipt" alt='{$tmp}' >
                  <a style="position:absolute;right:20px;color:#ccc" href="#" onclick="clr('{$k}')"><i class="icon icon-times"></i></a>
                  <span class="caret"></span>
              </span>
              <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel_{$tmp}" id='dropdown_{$tmp}'>
                <volist name="$k" id='vo'>
                <li><a onclick=showoption("{$k}",<?php echo $vo[$tmp.'id'] ?>,"<?php echo $vo[$tmp.'nm'] ?>")><?php echo $vo[$tmp.'nm'] ?></a></li>
                </volist>
              </ul>
          </span>
      <?php }else{ ?>
      <select id='{$k}'>
        <option value='0'>无</option>
        <?php //处理萃取下主题
                  $tmp=explode('_', $k);$tmp=explode('id',$tmp[2]);$tmp=$tmp[0];
                ?>
        <volist name='$k' id='v'><option value="<?php echo $v[$tmp.'id'] ?>"><?php echo $v[$tmp.'nm'] ?></option></volist>
      </select>
      <?php } ?>
      <?php }else if(isset($transmean[$k])){ ?>
      <select id='{$k}'>
        <?php foreach($transmean[$k] as $v=>$dsc){ ?>
        <option value="{$v}">{$dsc}</option>
        <?php } ?>
      </select>
      <?php }else{ ?>
      <?php if($inputtm[$k]){ ?>
      <?php if($inputtm[$k]==1){ ?>
      <script language="javascript" type="text/javascript" src="__PUBLIC__/etc/DatePicker/My97DatePicker/WdatePicker.js"></script>
      <?php }else{ ?>
      <script language="javascript" type="text/javascript" src="__PUBLIC__/etc/DatePicker/My97DatePickerHHmmss/WdatePicker.js"></script>
      <?php } ?>
      <input id='{$k}' onclick="WdatePicker()" readonly>
      <?php }else{ ?>
      <input id='{$k}'>
      <?php } ?>
      <?php } ?>
      <script>var k="{$k}";var v="{$moforjs[$k]}";if(k.indexOf('_')!=-1&&v==''){$('#'+k).val('0');}else{$('#'+k).val(v);}</script>
      </td></tr>
      <?php }
      } ?>
    </tbody>
  </table>
  <a class='btn btn-primary' id='update'><?php if($id==0){ ?>添加<?php }else{ ?>修改<?php } ?></a>
</div>

<script>
//自身参数，初始数据
var para=new Object();
var selfpara=new Array();
var origindata=new Object();

<?php 
foreach($para as $k=>$v){ 
  if(!in_array($k, $notself)){
?>
para["{$k}"]="{$v}";
selfpara.push("{$k}");
origindata["{$k}"]="{$moforjs[$k]}";
<?php 
  }
} 
?>

//不用管的，也不用显示的
var no_update=new Array();
<?php 
foreach($no_update as $nuv){ 
?>
no_update.push("{$nuv}");
<?php 
} 
?>
//zabojin的属性里面在显示中，允许空的
var allowempty=new Array();
<?php 
foreach($allowempty as $aev){ 
?>
allowempty.push("{$aev}");
<?php 
} 
?>
//transmean
var transmeank=new Array();
<?php 
foreach($transmean as $tmvk=>$tmvv){ 
?>
transmeank.push("{$tmvk}");
<?php 
} 
?>

//#########
$(function(){
  $('#update').click(function(){


    //ctt III start
    <?php foreach($ctt as $k_ctt){ ?>
    $('#{$k_ctt}').val(editor['{$k_ctt}'].getContent());
    <?php } ?>
    //ctt III over

    //首先把相关的参数数据聚集起来，把自身更新需要的参数以及变动的数据进行传输
    //由于第一个往往是id所以，就不去考虑了
    //先判断是否为空
    for(var i=1;i<selfpara.length;i++){
      var key=selfpara[i];var tmp=$('#'+key);
      //如果是允许空的，就不用考虑他有没有空的事情了；反之不在这里头，就要考虑了
      if(no_update.indexOf(key)==-1&&allowempty.indexOf(key)==-1){var tagname=tmp.get(0).tagName;
        if(tagname=='INPUT'&&$.trim(tmp.val())==''){
          msg(para[key]+'不能为空');tmp.focus();return;
        }else if(transmeank.indexOf(key)==-1&&tagname=='SELECT'&&$.trim(tmp.val())=='0'){
          msg(para[key]+'未选择');tmp.focus();return;
        }
      }
      
    }
    //然后判断哪些是有变动的，变动的数值需要提交修改，没有变动的则直接不用接后台了
    //其中添加需要全盘给上，修改只用给变量就行
    if(addormdf!=0){
      var flag_change=0;
      for(var i=1;i<selfpara.length;i++){
        //排除掉不用管的
        var key=selfpara[i];var tmp=$('#'+key);var valuenow=$.trim(tmp.val());
        if(no_update.indexOf(key)==-1){
          if(valuenow!=origindata[key]){
            flag_change=1;
            obj[key]=valuenow;
          }
        }
      }
      if(flag_change==0){msg('没有任何信息改变');return;}
    }else{
      for(var i=1;i<selfpara.length;i++){
        var key=selfpara[i];var tmp=$('#'+key);var valuenow=$.trim(tmp.val());
        if(no_update.indexOf(key)==-1){
          obj[key]=valuenow;
        }
      }
    }
    
    $.post(
      doupdate,
      obj,
      function(data){
        
        var str='';
              if(data['pattern']=='0'){str='添加';}else{str='修改';}
              msg(str+'成功！点击返回',2);
              
                console.log("success");
      
      
      },
      'json'
    );
    // $.ajax({
    //         'type': 'GET',
    //         'url':doupdate,
    //         'async':false,  
    //         'contentType': 'application/json',
    //         'data': obj,
    //         'dataType': 'json',
    //         'success': function(data) {
    //           var str='';
    //           if(data['pattern']=='0'){str='添加';}else{str='修改';}
    //           msg(str+'成功！点击返回',2);
    //           console.log("success");
    //         },
    //         'error':function() {
    //             console.log("error");
    //         }
    //     });
  })
})
</script>

<script>

$(function(){
  //记录
  var ipf=new Array();
  <?php foreach($impactfactor as $ifv){ ?>
    ipf.push("{$ifv}");
  <?php } ?>
  <?php foreach($impactfactor as $ifv){ ?>
    $('#'+"{$ifv}").change(function(){
      var obj=new Object();
      obj['trigger']="{$ifv}";
      for(var i=0;i<ipf.length;i++){
        obj[ipf[i]]=$('#'+ipf[i]).val();
      }
      $.ajax({
          'type': 'GET',
          'url':dolinkage,
          'async':false,  
          'contentType': 'application/json',
          'data': obj,
          'dataType': 'json',
          'success': function(data) {
            for(var i=0;i<data.length;i++){
              var aim=data[i]['aim'];
              var str="<option value='0'>无</option>";
              if(data[i]['ls']){
                for(var j=0;j<data[i]['ls'].length;j++){
                  str=str+"<option value='"+data[i]['ls'][j][data[i]['prex']+'id']+"'>"+data[i]['ls'][j][data[i]['prex']+'nm']+"</option>"
                }
            }
              $('#'+aim).html(str);
            }
          },
          'error':function() {
            console.log("error");
          }
      });
    })
  <?php } ?>
})

$('.keyipt').keyup(function(){
  
  var kw=$(this).val();//key word
  var cls=$(this).attr('alt');
  var keyid=$(this).attr('id').split('_ipt')[0];

  $.ajax({
      'type': 'GET',
      'url':dogetinputselectlsbykw,
      'async':false,  
      'contentType': 'application/json',
      'data': {'kw':kw,'cls':cls},
      'dataType': 'json',
      'success': function(data) {
        var mls=data['mls'];
        var str='';
        
        if(mls){  
          for(var i=0;i<mls.length;i++){
            mv=mls[i];
            str=str+"<li><a onclick=showoption('"+keyid+"','"+mv[cls+'id']+"','"+mv[cls+'nm']+"')>"+mv[cls+'nm']+"</a></li>";
          }
        }
        
        $('#dropdown_'+cls).html(str);
        
        console.log("success");
      },
      'error':function() {
        console.log("error");
      }
  });
})

function  showoption(idnm,id,nm){
  $('#'+idnm).val(id);
  $('#'+idnm+"_ipt").val(nm+'[已选]');
  
}

function clr(id){
  $('#'+id).val(0);
  $('#'+id+"_ipt").val("");
}
</script>